//
//  BySomeCirclesView.m
//  caipiao_ios
//
//  Created by mc on 2018/6/29.
//  Copyright © 2018年 ZhangZhanbin. All rights reserved.
//

#import "BySomeCirclesView.h"

@implementation BySomeCirclesView

- (UIColor *)themeColor{
    if (_themeColor) {
        _themeColor = BY_THEME_COLOR;
    }
    return _themeColor;
}

- (void)setItemsAry:(NSArray *)itemsAry{
    _itemsAry = itemsAry;

    CGFloat left = 10;
    CGFloat magin = 15;
    CGFloat width = (SCREEN_WIDTH - 10 - left * 2 - magin * 6) / 7.0;
    for (int i = 0;i < _itemsAry.count; i++) {
        ByNetModel *netModel = [_itemsAry objectAtIndex:i];
        UILabel *valueLabel = [[UILabel alloc] initWithFrame:CGRectMake(left + i % 7 * (width + magin), i / 7 * (width + magin), width, width)];
        [self addSubview:valueLabel];
        valueLabel.layer.cornerRadius = width / 2.0;
        if (netModel.value < 10) {
            valueLabel.text = [NSString stringWithFormat:@"0%ld",netModel.value];
        }else{
            valueLabel.text = [NSString stringWithFormat:@"%ld",netModel.value];
        }
        
        valueLabel.tag = 100 + i;
        valueLabel.font = FONT(14);
        valueLabel.textAlignment = NSTextAlignmentCenter;
        valueLabel.layer.masksToBounds = YES;
        
        if (netModel.selected) {
            valueLabel.textColor = [UIColor whiteColor];
            valueLabel.backgroundColor = _themeColor;
            
        }else{
            valueLabel.textColor = _themeColor;
            valueLabel.layer.borderColor = _themeColor.CGColor;
            valueLabel.layer.borderWidth = 1;
        }
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
        [valueLabel addGestureRecognizer:tap];
        valueLabel.userInteractionEnabled = YES;
     }
}

+ (CGFloat)getHeighWithItemsAry:(NSArray *)itemsAry{
    CGFloat left = 10;
    CGFloat magin = 15;
    CGFloat width = (SCREEN_WIDTH - 20 - left * 2 - magin * 6) / 7.0;
    
    return (width + magin) * ((itemsAry.count - 1) / 7  + 1);
}

- (void)tapAction:(UITapGestureRecognizer *)tap{
    
    if (self.selectBlock) {
        self.selectBlock(tap.view.tag - 100);
    }
}



@end
